<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            margin: 50px 0;
            position: absolute;
            top: 0;
            left: 0;
            width: 100px;
            height: 100px;
            background-color: pink;
        }
    </style>
</head>
<body>
    <button>点我</button>
    <div></div>
</body>
<script>
    var btn = document.querySelector('button')
    var divs = document.querySelector('div')
    var target = 500 //目标值
    var leader = 0 //步长
//为按钮注册一个点击事件
    btn.onclick = function(){
        setInterval(() => {
        //缓动学公式  leader = leader + (target - leader ) / 10
        leader = leader + (target - leader ) / 10
        divs.style.left = leader + 'px'
    }, 30);
    }
</script>
</html>